package com.yf.course.modules.course.controller;

import com.yf.ability.log.annon.LogInject;
import com.yf.ability.log.enums.LogType;
import com.yf.base.api.annon.DataProtect;
import com.yf.base.api.api.ApiRest;
import com.yf.base.api.api.controller.BaseController;
import com.yf.course.modules.course.dto.ext.CourseDetailExtDTO;
import com.yf.course.modules.course.entity.Course;
import com.yf.course.modules.course.service.CourseSocketService;
import com.yf.course.websocket.server.SystemEndpoint;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.Session;
import java.io.IOException;

/**
 * <p>
 * 课程中使用socket向前端主动发送消息的控制器
 * </p>
 */
@Api(tags = {"课程socket"})
@RestController
@RequestMapping("/api/course/socket")
public class CourseSocketController extends BaseController {
    @Autowired
    private CourseSocketService courseSocketService;

    /**
     * 数字人生成成功或失败的处理
     * @param courseId 课程ID
     * @param flag 成功、失败的标志
     */
    @ApiOperation(value = "数字人生成成功或失败的处理")
    @GetMapping("/digitalPerson")
    public ApiRest digitalPerson(@RequestParam(value = "courseId") String courseId, @RequestParam(value = "flag") Boolean flag) {
        String result = courseSocketService.digitalPerson(courseId, flag);
        if (result.equals("操作成功")) {
            return super.success();
        } else {
            return super.failure(result);
        }
    }

    /**
     * 知识点抽取生成或失败的处理
     * @param courseId 课程ID
     * @param flag 成功、失败的标志
     */
    @ApiOperation(value = "知识点抽取成功或失败的处理")
    @GetMapping("/knowledgePoint")
    public ApiRest knowledgePoint(@RequestParam(value = "courseId") String courseId, @RequestParam(value = "flag") Boolean flag) {
        String result = courseSocketService.knowledgePoint(courseId, flag);
        if (result.equals("操作成功")) {
            return super.success();
        } else {
            return super.failure(result);
        }
    }
}
